var pendingQueryDetail = {
    saleAreas:[],//销售区域
    init: function () {
        if (getQueryString('params')) {
            var skuId = getQueryString('params');
            this.getDetailData([skuId]);
        }
        this.addClick()

    },
    addClick:function (){
        // 销售区域操作
        $('.saleAreaWarp').delegate('li','click',function(){
            var provinceCode = $(this).attr('data-code')
            var str = '';
            $.each(pendingQueryDetail.saleAreas,function(index,item){
                if(provinceCode == item.code){
                    $.each(item.children,function(index,itm){
                        str +='<span>'+itm.name+'、</span>'
                    })
                }
            })
            layer.alert(str,{title:'销售区域',offset:'t'})
        })
    },
    // 请求详情接口
    getDetailData: function (skuAuditRecordIds) {
        var params = {
            skuAuditRecordIds: skuAuditRecordIds
        }
        var successData = function (data) {
            if (data.errorCode == 0) {
                pendingQueryDetail.renderDetailDataOne(data.data)
                pendingQueryDetail.renderDetailTwo(data.data)
                pendingQueryDetail.renderDetailThree(data.data.skus)
                pendingQueryDetail.renderDetailFourth(data.data)
            }
        }
        return web.doAjax(root.serviceProviderManagement.getAuditProductDetail, 'post', params, successData, 1)
    },
    // 数据渲染一
    renderDetailDataOne: function (result) {
        /*模块一数据 start */
        var providerName = result.providerName ? result.providerName : '';// 服务商名称
        var customerName = result.channelName ? result.channelName : '';// 专属客户
        var auditStatus = '';  // 状态
        if (result.skus[0].auditStatus == 10) {
            auditStatus = '待审核';
        } else if (result.skus[0].auditStatus == 20) {
            auditStatus = '审核通过';
        } else if (result.skus[0].auditStatus == 30) {
            auditStatus = '审核驳回';
        } else {
            auditStatus = '';
        }
        var updateTime = result.skus[0].updateTime;// 更新时间
        var auditUserName = result.skus[0].auditUserName; // 审核人
        var auditTime = result.skus[0].auditTime;// 审核时间
        var auditFailReason = result.skus[0].auditFailReason ? result.skus[0].auditFailReason : '';// 驳回原因
        // 驳回原因
        /*模块一数据回显 start*/
        $('.providerName').html(providerName);
        $('.customerName').html(customerName);
        $('.auditStatus').html(auditStatus);
        $('.updateTime').html(updateTime);
        $('.auditUserName').html(auditUserName);
        $('.auditTime').html(auditTime);
        $('.auditFailReason').html(auditFailReason);
        /*模块一数据回显 end */
    },
    // 数据渲染二
    renderDetailTwo: function (result) {
        /*模块二数据 start*/
        var spuName = result.spuName ? result.spuName : '';//商品名称
        var oneCategoryName = result.oneCategoryName ? result.oneCategoryName : '';//一级名称
        var twoCategoryName = result.twoCategoryName ? result.twoCategoryName : '';//二级名称
        var threeCategoryName = result.threeCategoryName ? result.threeCategoryName : '';//三级名称
        var fourthCategoryName = result.fourCategoryName ? result.fourCategoryName:'';// 四级分类名称
        var classificationName = result.classificationName ? result.classificationName : '';//归类名称
        var revenueCode = result.revenueCode ? result.revenueCode : '';//税类编码
        var definitionBrandName = result.definitionBrandName;// 自定义品牌名称
        var brandName = result.brandName ? result.brandName : definitionBrandName;//云采品牌

        var origin = result.origin ? result.origin : '';//产地
        var material = result.material ? result.material : '';//材质
        var restricted = '';//限制类型
        if (result.categoryProductType == 1) {
            restricted = '危化品'
        } else if (result.categoryProductType == 2) {
            restricted = '管制刀具'
        } else {
            restricted = '非限制类'
        }
        var spuImages = result.spuImages; //// 渲染图片
        var productQualifications = result.productQualifications;//商品资质
        // 商品资质
        if(productQualifications){
            $('.product_qualification').show()
            $('#downLoadQualification').attr('href',root.orderInter.downLoadFromUrl +'?urlStr='+productQualifications+'&fileName=下载pdf模板')
        }else {
            $('.product_qualification').hide();
        }
        // 渲染图片
        if (spuImages.length > 0) {
            var str = '';
            spuImages.forEach(function (item) {
                str += '<li class="right" data-src="'+item.attachmentUrl+'" onclick="pendingQueryDetail.checkBigPic(this)">' +
                    '<img src="' + item.attachmentUrl + '" alt="" style="width: 50px;height: 50px">' +
                    '  </li>'
            });
            var newStr = '<li class="left">图片：</li>' + str
            $('.picture').html(newStr)
        }
        /* 添加四级分类---------------------------------------------------------------- -*/

        var classifyHtml = '<span>' + oneCategoryName + '</span> > <span>' + twoCategoryName + '</span> > <span>' + threeCategoryName + '</span> > <span>'+fourthCategoryName+'</span>';

        // 销售区域
        var saleAreas = result.saleAreas?result.saleAreas:[];
        pendingQueryDetail.saleAreas = saleAreas;
        var strArea = '';
        if(saleAreas.length >0){
            var strArea = '';
            if(saleAreas[0].code == 0){
                $.each(saleAreas,function(index,item){
                    strArea +=' <li style="cursor: pointer;display: inline-block;margin-right: 7px" data-code="'+item.code+'">'+item.name+''+'</li>'
                });
            }else{
                $.each(saleAreas,function(index,item){
                    strArea +=' <li style="cursor: pointer;display: inline-block;margin-right: 7px" data-code="'+item.code+'">'+item.name+'' +
                        ' <span style="color: #0a60d6">('+item.children.length+')</span>' +
                        '</li>'
                });
            }

            $('.saleAreaWarp').html(strArea);
        }
        $('.defaultClassify').html(classifyHtml)
        /* 模块二数据回显 start */
        $('.spuName').html(spuName);
        $('.classificationName').html(classificationName);
        $('.revenueCode').html(revenueCode);
        $('.brandName').html(brandName);
        $('.origin').html(origin);
        $('.material').html(material);
        $('.restricted').html(restricted);


    },
    // 数据渲染三
    renderDetailThree: function (result) {
        if (result.length > 0) {
            var str = ''
            $.each(result, function (index, item) {
                var specifications = item.specifications ? item.specifications : '';
                var color = item.color ? item.color : '';
                var channelPrice = item.channelPrice ? item.channelPrice.toFixed(2) : 0.00;
                var xfsPurchasePrice = item.xfsPurchasePrice ? item.xfsPurchasePrice.toFixed(2) : 0.00;
                var deliveryDay = item.deliveryDay ? item.deliveryDay : 0;
                var miniOrder = item.miniOrder? item.miniOrder:0;
                var unitName = item.unitName;//单位
                var maxLength = item.maxLength?item.maxLength:0;//最长边
                var volume = item.volume?item.volume:0;//体积
                var weight = item.weight?item.weight:0;//重量
                str += ' <tr>' +
                    '            <td>' + specifications + '</td>' +
                    '            <td>' + color + '</td>' +
                    '            <td>¥' + channelPrice + '/' + item.unitName + '</td>' +
                    '            <td>¥' + xfsPurchasePrice + '/' + item.unitName + '</td>' +
                    '            <td>' + deliveryDay + '天</td>' +
                    '            <td>' + miniOrder + "" + unitName+'</td>' +
                    '            <td>' + maxLength +'cm</td>' +
                    '            <td>' + volume +'m³</td>' +
                    '            <td>' + weight + 'kg</td>' +
                    '        </tr>'
            });
            $('.tbody').html(str)
        } else {
            var empty =
                ' <tr>' +
                '<td colspan=5>暂无数据</td>' +
                '</tr>';
            $('.tbody').html(empty)
        }

    },
    // 数据渲染四
    renderDetailFourth: function (result) {
        $('.detail').html(result.detail)
    },
    // 点击查看大图
    checkBigPic:function(imgSrc){
        var imgUrl = $(imgSrc).attr('data-src')
        var title = '查看图片';
        var url = '../../goods/picShow.html';
        window.event ? window.event.cancelBubble = true : e.stopPropagation();
        sessionStorage.setItem("imgUrl", imgUrl);
        layer_show(title, url, "800", "500");
    }

}
pendingQueryDetail.init()